import { createElement } from "react";
import { createRoot } from 'react-dom/client';
const Wrap = (component) => {
  const distoryDialog = (root) => {
    if (root) {
      root.unmount();
    }
  }

  return (config) => {
    const dom = document.createElement('div');
    let root = createRoot(dom);
    // 定义一个jsx组件
    let jsxComponent = createElement(component, {
      ...config,
      visiable: true,
      closeDialog: () => {
        distoryDialog(root);
      }
    })

    // 渲染组件
    root.render(jsxComponent);
  }
}

export default Wrap;